<template>
	<view class="circletime" v-if="showcircletime">
		<view class="main">
			<view class="number">
				<text>{{t}}</text>
			</view>
		</view>
	</view>
</template>

<script setup> 
import {ref,watch,nextTick} from "vue";
const props=defineProps({
	time:{
		type:String,//定义数据的类型
		reqiured:false,//是否必须
		default:3,//默认值
	}
});
const emit=defineEmits();
let showcircletime=ref(false);
let t=ref(props.time);
let renderDeg=ref(`conic-gradient(#189805 0%, #189805 0deg, #fff 0deg, #fff 360deg)`);
let timeControl=ref(null);
function timer(){
	t.value=props.time;
	function setTime(){
		timeControl.value=setTimeout(()=>{
			t.value--;
			if(t.value>0){
				setTime();
			}else{
				setTimeout(()=>{
					hideShow();
					emit("closeTime");
				},300)
			}
		},1000)
	}
	setTime();
}
watch(t,(newV)=>{
	let gapDeg=(360/props.time)+1;
	let nowDeg=(props.time-newV)*gapDeg;
	renderDeg.value=`conic-gradient(#189805 0%, #189805 ${nowDeg}deg, #fff ${nowDeg}deg, #fff 360deg)`
})
function openShowCircletime(){
	showcircletime.value=true;
	nextTick(()=>{
		timer();
	})
}
function hideShowCircletime(){
	clearTimeout(timeControl.value);
	showcircletime.value=false;
}
defineExpose({
	openShow,
	hideShow,
});
</script>

<style lang="less" scoped>
.circletime{
	width: 100%;
	height: 100vh;
	position: fixed;
	z-index: 8;
	background-color: rgba(0, 0, 0, 0.39);
	top: 0;
	left: 0;
	.main{
		width: 197rpx;
		height: 197rpx;
		border-radius: 50%;
		position: absolute;
		left: 0;
		right: 0;
		top: 30%;
		margin: auto;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		background: v-bind(renderDeg);
		transition: .3s;
		.number{
			width: 178rpx;
			height: 178rpx;
			background-color: #fff;
			border-radius: 50%;
			font-weight: bold;
			font-size: 84rpx;
			color: #151515;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			padding-bottom: 8rpx;
			box-sizing: border-box;
		}
	}
}
</style>